package com.wangshang.team.order.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.team.order.po.TeamShopOrder;
import com.wangshang.team.order.po.TeamShopOrderId;

/**
 * A data access object (DAO) providing persistence and search support for
 * TeamShopOrder entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wangshang.team.order.po.TeamShopOrder
 * @author MyEclipse Persistence Tools
 */

public class TeamShopOrderDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TeamShopOrderDAO.class);
	// property constants
	public static final String WORK_ID = "workId";
	public static final String HALL_ID = "hallId";
	public static final String USER_NAME = "userName";
	public static final String USER_ID_TYPE = "userIdType";
	public static final String USER_ID = "userId";
	public static final String USER_CONNECT = "userConnect";
	public static final String USER_ADDR = "userAddr";
	public static final String CASH_PAY = "cashPay";
	public static final String TOTAL_COST = "totalCost";
	public static final String ORDER_STATUS = "orderStatus";
	public static final String WAY_OF_DELIVERY = "wayOfDelivery";
	public static final String PLACE_ID = "placeId";
	public static final String PLACE_MASK = "placeMask";
	public static final String RESULT_FOR_UNEXPECTED = "resultForUnexpected";

	protected void initDao() {
		// do nothing
	}

	public void save(TeamShopOrder transientInstance) {
		log.debug("saving TeamShopOrder instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TeamShopOrder persistentInstance) {
		log.debug("deleting TeamShopOrder instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TeamShopOrder findById(com.wangshang.team.order.po.TeamShopOrderId id) {
		log.debug("getting TeamShopOrder instance with id: " + id);
		try {
			TeamShopOrder instance = (TeamShopOrder) getHibernateTemplate()
					.get("com.wangshang.team.order.TeamShopOrder", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TeamShopOrder instance) {
		log.debug("finding TeamShopOrder instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TeamShopOrder instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TeamShopOrder as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByWorkId(Object workId) {
		return findByProperty(WORK_ID, workId);
	}

	public List findByHallId(Object hallId) {
		return findByProperty(HALL_ID, hallId);
	}

	public List findByUserName(Object userName) {
		return findByProperty(USER_NAME, userName);
	}

	public List findByUserIdType(Object userIdType) {
		return findByProperty(USER_ID_TYPE, userIdType);
	}

	public List findByUserId(Object userId) {
		return findByProperty(USER_ID, userId);
	}

	public List findByUserConnect(Object userConnect) {
		return findByProperty(USER_CONNECT, userConnect);
	}

	public List findByUserAddr(Object userAddr) {
		return findByProperty(USER_ADDR, userAddr);
	}

	public List findByCashPay(Object cashPay) {
		return findByProperty(CASH_PAY, cashPay);
	}

	public List findByTotalCost(Object totalCost) {
		return findByProperty(TOTAL_COST, totalCost);
	}

	public List findByOrderStatus(Object orderStatus) {
		return findByProperty(ORDER_STATUS, orderStatus);
	}

	public List findByWayOfDelivery(Object wayOfDelivery) {
		return findByProperty(WAY_OF_DELIVERY, wayOfDelivery);
	}

	public List findByPlaceId(Object placeId) {
		return findByProperty(PLACE_ID, placeId);
	}

	public List findByPlaceMask(Object placeMask) {
		return findByProperty(PLACE_MASK, placeMask);
	}

	public List findByResultForUnexpected(Object resultForUnexpected) {
		return findByProperty(RESULT_FOR_UNEXPECTED, resultForUnexpected);
	}

	public List findAll() {
		log.debug("finding all TeamShopOrder instances");
		try {
			String queryString = "from TeamShopOrder";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TeamShopOrder merge(TeamShopOrder detachedInstance) {
		log.debug("merging TeamShopOrder instance");
		try {
			TeamShopOrder result = (TeamShopOrder) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TeamShopOrder instance) {
		log.debug("attaching dirty TeamShopOrder instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TeamShopOrder instance) {
		log.debug("attaching clean TeamShopOrder instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TeamShopOrderDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TeamShopOrderDAO) ctx.getBean("TeamShopOrderDAO");
	}
}